package com.nuist.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuist.mapper.ElectricMapper;
import com.nuist.entity.Electric;
import com.nuist.service.ElectricService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author 梁科
 * @Version 1.0
 * @ Date 2025/10/16 23:29
 */
@Service
public class ElectricServiceImpl extends ServiceImpl<ElectricMapper, Electric>
        implements ElectricService {

    @Resource
    private ElectricMapper electricMapper;

    /**
     * 将电器信息保存到数据库(删除redis缓存数据 key = Electric)
     * @param electric
     */
    @Override
    @CacheEvict(cacheNames = "Electric",allEntries = true)
    public void saveElectric(Electric electric) {
        electricMapper.saveElectric(electric);
    }

    /**
     * 更新电器信息(删除redis缓存数据 key = Electric)
     * @param electric
     */
    @Override
    @CacheEvict(cacheNames = "Electric",allEntries = true)
    public void updateElectric(Electric electric) {
        electricMapper.updateElectric(electric);
    }
}
